import { getGoodsList, getSort } from "api/api";
export default {
    state: {
        attrsList: [],
        goodsList: [],
        total: 0,
        trademarkList: [],
        sortTypes: []

    },
    getters: {},
    mutations: {
        getGoodsList(state, { goodsList, total, trademarkList, attrsList }) {
            state.goodsList = goodsList;
            state.trademarkList = trademarkList;
            state.attrsList = attrsList;
            state.total = total
        },
        getSortTypes(state, sortTypes) {
            state.sortTypes = sortTypes
        }
    },
    actions: {
        async getGoodsList(store, options) {
            try {
                const { code, data: searchData } = await getGoodsList(options);
                if (code === 200) {
                    //请求成功 并成功获取到三级分类的数据
                    if (searchData.goodsList)
                        store.commit("getGoodsList", {
                            goodsList: searchData.goodsList,
                            total: searchData.total,
                            attrsList: searchData.attrsList,
                            trademarkList: searchData.trademarkList
                        })
                }
                return { code, data: searchData }
            } catch (e) {
                return Promise.reject(e)
            }
        },
        async getSort(store) {
            try {
                const { code, data: sortTypes } = await getSort();
                if (code === 200) {
                    store.commit("getSortTypes", sortTypes)
                }
                return { code, data: sortTypes }
            } catch (e) {
                return Promise.reject(e)
            }
        }
    }
}